/**
 * @file dac.c
 * @brief Serial Interface
 *
 * @version Fixed
 * @author yemit
 * @date 2010-06-17
 */
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <key.h>
#include "config.h"
#include "device.h"
#include "dac.h"

static int dac_fd = -1;
int dac_dev_init(void)
{
        dac_fd = open("/dev/dac", O_RDWR|O_NONBLOCK);
}

int dac_init(dac_info_t *param)
{
        return ioctl(dac_fd, IOCTL_DAC_SET_PARAM, param);
}

int dac_write(uint8_t *buf, ssize_t len)
{
        int ret, size = len;
        while (size) {
                ret = write(dac_fd, buf, size);
                buf += ret;
                size -= ret;
        }
        return len;
}
void dac_loop(uint8_t onoff)
{
        ioctl(dac_fd, IOCTL_DAC_LOOP, onoff);
}

